package com.example.demo.Service;

import com.example.demo.Bean.Member;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MemberService {
    @Autowired
    private UserService userService;

    @Autowired
    private EmailService emailService;

    @RabbitListener(queues = "email")
    public void sendEmail(Member member) {
        try{
            String name = member.getUsername();
            String email = member.getEmail();
            System.out.println("AMOP接收成功");
            String content = "欢迎: " + name + "成为普通用户 赠送您200积分";
            userService.updateUserIntegral(name);
            emailService.sendSimpleMail(email, "注册成功", content);
            System.out.println("AMOP邮件发送成功");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
